package com.ruoyi.web.controller.yf;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.yf.domain.YfException;
import com.ruoyi.yf.service.IYfExceptionService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 条形码异常记录Controller
 * 
 * @author XiaoYi...
 * @date 2020-03-17
 * 4c2a59b2-f15d-403c-a7b2-69710aec963e
 */
@Controller
@RequestMapping("/yf/exception")
public class YfExceptionController extends BaseController
{
    private String prefix = "yf/exception";

    @Autowired
    private IYfExceptionService yfExceptionService;

    @RequiresPermissions("yf:exception:view")
    @GetMapping()
    public String exception()
    {
        return prefix + "/exception";
    }

    /**
     * 6344f57f-ad49-4f2d-9a59-4fef6e38a1e6
     * 查询条形码异常记录列表
     */
    @RequiresPermissions("yf:exception:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(YfException yfException)
    {
        startPage();
        List<YfException> list = yfExceptionService.selectYfExceptionList(yfException);
        return getDataTable(list);
    }

    /**
     * 4210afa0-fab4-4636-9a5a-e20d23d7cacb
     * 导出条形码异常记录列表
     */
    @RequiresPermissions("yf:exception:export")
    @Log(title = "条形码异常记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(YfException yfException)
    {
        List<YfException> list = yfExceptionService.selectYfExceptionList(yfException);
        ExcelUtil<YfException> util = new ExcelUtil<YfException>(YfException.class);
        return util.exportExcel(list, "exception");
    }

    /**
     * 新增条形码异常记录
     * 35c45e97-2710-4f2b-84d5-b32eedafbe84
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存条形码异常记录
     * f390beaf-e1f3-46b1-8c36-1c6ff1c27475
     */
    @RequiresPermissions("yf:exception:add")
    @Log(title = "条形码异常记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(YfException yfException)
    {
        return toAjax(yfExceptionService.insertYfException(yfException));
    }

    /**
     * 修改条形码异常记录
     * 91d29dde-81ba-422b-b6b0-a9f63995a551
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        YfException yfException = yfExceptionService.selectYfExceptionById(id);
        mmap.put("yfException", yfException);
        return prefix + "/edit";
    }

    /**
     * 修改保存条形码异常记录
     * a06399c3-74b1-4459-b961-262c7f33918d
     */
    @RequiresPermissions("yf:exception:edit")
    @Log(title = "条形码异常记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(YfException yfException)
    {
        return toAjax(yfExceptionService.updateYfException(yfException));
    }

    /**
     * 删除条形码异常记录
     * b6f430cc-707f-4d94-8dc5-860aacc1e869
     */
    @RequiresPermissions("yf:exception:remove")
    @Log(title = "条形码异常记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(yfExceptionService.deleteYfExceptionByIds(ids));
    }
}
